import { maxFloor, DIRECTION, rateSrc1 } from "./define";

export const GetFloorNumArr = () => new Array(maxFloor).fill(0).map((v, i) => i + 1);

export const DeepCloneMap = (m) => {
  return new Map(Map2Array(m));
};

export const GetRandomOneToMaxF = () => Math.round(Math.random() * (maxFloor - 1)) + 1;
export const GetRandomMoreOneF = () => (Math.random() < rateSrc1 ? 1 : GetRandomOneToMaxF());

export const Map2Array = (m) => {
  return [...m.entries()];
};

export const Array2Map = (arr) => {
  return new Map(arr);
};

export const DelRepeat = (arr) => {
  return [...new Set(arr)];
};
/**
 * 向下队列，倒序排列
 * @param {*} arr
 */
export const SortDown = (arr) => {
  SortByDirection(arr, DIRECTION.DOWN);
};

/**
 * 向上队列，正序排列
 * @param {*} arr
 */
export const SortUp = (arr) => {
  SortByDirection(arr, DIRECTION.UP);
};

export const SortByDirection = (arr, direction) => {
  switch (direction) {
    case DIRECTION.UP:
      arr.sort((a, b) => a - b);
      break;
    case DIRECTION.DOWN:
      arr.sort((a, b) => b - a);
      break;
    case DIRECTION.NONE:
      return;
    default:
      return;
  }
};
/**
 * easeInOutQuart 缓动函数，动画用
 * @param {Number} t Time - 表示动画开始以来经过的时间。通常从0开始，通过游戏循环或update函数来缓慢增加
 * @param {Number} b Beginning value - 动画的起点，默认从0开始
 * @param {Number} c Change in value - 从起点到终点的差值
 * @param {Number} d Duration - 完成动画所需的时间
 * @returns
 */
export function EaseInOutQuart(t, b, c, d) {
  if ((t /= d / 2) < 1) return (c / 2) * t * t * t * t + b;
  return (-c / 2) * ((t -= 2) * t * t * t - 2) + b;
}
